version: "3.9"

volumes:
  redis-data:

services:

  frontend:
    image: nginx
    restart: always
    ports:
      - "8888:80"
    volumes:
      - "./static:/var/www/static"
      - "./nginx/default.conf:/etc/nginx/conf.d/default.conf"
    depends_on:
      - backend

  redis:
    image: redis
    restart: always
    volumes:
      - "redis-data:/data"
    healthcheck:
      test: [ "CMD", "redis-cli", "ping" ]
      timeout: 20s
      retries: 10

  celery: &backend
    build: .
    image: ecstasy:v.15.2
    restart: always
    command: celery -A ecstasy_project worker -B -l INFO -c 4 -n worker1
    environment:
      ALLOWED_HOSTS: "*"
      REDIS_CACHE_URL: "redis:6379/0"
      REDIS_BROKER_URL: "redis:6379/1"
      DATABASES: |
        {
            "default": {
                "ENGINE": "django.db.backends.mysql",
                "NAME": "ecstasy",
                "USER": "ecstasy",
                "PASSWORD": "ecstasy_password",
                "HOST": "mysql",
                "PORT": "3306"
            }
        }
      DJANGO_SECRET_KEY: "django-key"
      CONFIG_STORAGE_DIR: "/configurations"

    depends_on:
      - backend
    volumes:
    - "./logs:/app/logs"

  backend:
    <<: *backend
    command: /bin/sh run.sh
    volumes:
    - "./run.sh:/app/run.sh"
    - "./logs:/app/logs"
    - "./static:/app/static"
    - "./media:/app/media"
    - "./map_layer_files:/app/media/map_layer_files"
    - "./configurations:/configurations"
    depends_on:
      redis:
        condition: service_healthy
      mysql:
        condition: service_healthy

  mysql:
    image: mysql
    environment:
      MYSQL_ROOT_PASSWORD: root_password
      MYSQL_USER: ecstasy
      MYSQL_PASSWORD: ecstasy_password
      MYSQL_DATABASE: ecstasy
    restart: always
    volumes:
      - "./data:/var/lib/mysql"
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      timeout: 20s
      retries: 10
